package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.SpecialPriceSystemDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.SpecialPriceSystemInfo;
import com.sls.game.querybean.SpecialPriceSystemQuery;

/**
 * 
 * @description 特殊价格体系DAO
 * @author Wangxuegang
 * @date 2012-10-12
 * 
 */
@Repository("specialPriceSystemDAO")
public class SpecialPriceSystemDAOImpl extends SuperDAO<SpecialPriceSystemInfo>
		implements SpecialPriceSystemDAO {

	/**
	 * 根据商品编号和价格模版编号，查询特殊价格体系表中，该商品的价格
	 * 
	 * @param info
	 * @return
	 */
	@Override
	public SpecialPriceSystemInfo queryOneRecord(SpecialPriceSystemInfo info) {
		SpecialPriceSystemInfo SpecialPriceInfo = null;
		SpecialPriceInfo = this.getSqlSession().selectOne(
				"mybatis.xml.SpecialPriceSystemMapper.queryOneRecord", info);

		return SpecialPriceInfo;
	}

	@Override
	public void insert(SpecialPriceSystemInfo specialPriceSystemInfo) {
		this.getSqlSession().insert(
				"mybatis.xml.SpecialPriceSystemMapper.insertPriceSystem",
				specialPriceSystemInfo);
	}

	@Override
	public void update(SpecialPriceSystemInfo specialPriceSystemInfo) {
		this.getSqlSession().update(
				"mybatis.xml.SpecialPriceSystemMapper.updatePriceSystem",
				specialPriceSystemInfo);
	}

	@Override
	public void delete(String id) {
		this.getSqlSession().delete(
				"mybatis.xml.SpecialPriceSystemMapper.deletePriceSystem", id);
	}

	@Override
	public Pagination<SpecialPriceSystemInfo> querySpecialPriceSystem(
			SpecialPriceSystemQuery specialPriceSystemQuery) {
		Integer rows = this.queryRowCount(specialPriceSystemQuery);
		specialPriceSystemQuery.calculate();
		List<SpecialPriceSystemInfo> list = this
				.queryPriceSystemList(specialPriceSystemQuery);
		Pagination<SpecialPriceSystemInfo> page = this.queryPagination(rows,
				list, specialPriceSystemQuery);
		return page;
	}

	/**
	 * 查询总记录数
	 * 
	 * @param specialPriceSystemQuery
	 * @return
	 */
	private Integer queryRowCount(
			SpecialPriceSystemQuery specialPriceSystemQuery) {
		Integer rows = 0;
		rows = this.getSqlSession().selectOne(
				"mybatis.xml.SpecialPriceSystemMapper.queryPriceSystemRow",
				specialPriceSystemQuery);

		return rows;
	}

	/**
	 * 查询结果记录集
	 * 
	 * @param specialPriceSystemQuery
	 * @return
	 */
	private List<SpecialPriceSystemInfo> queryPriceSystemList(
			SpecialPriceSystemQuery specialPriceSystemQuery) {
		List<SpecialPriceSystemInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.SpecialPriceSystemMapper.queryPriceSystemList",
				specialPriceSystemQuery);
		return list;
	}

	@Override
	public SpecialPriceSystemInfo queryPriceSystemByGoodsIdAndTemplateCode(
			SpecialPriceSystemInfo specialPriceSystemInfo) {
		SpecialPriceSystemInfo priceInfo = this
				.getSqlSession()
				.selectOne(
						"mybatis.xml.SpecialPriceSystemMapper.queryPriceSystemByGoodsIdAndTemplateCode",
						specialPriceSystemInfo);
		return priceInfo;
	}

	@Override
	public List<SpecialPriceSystemInfo> queryPriceSystemsByGoodsId(
			String goodsId) {
		List<SpecialPriceSystemInfo> priceInfo = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.SpecialPriceSystemMapper.queryPriceSystemByGoodsId",
						goodsId);
		return priceInfo;
	}

	@Override
	public void updateTemplateName(SpecialPriceSystemInfo specialPriceSystemInfo) {
		this.getSqlSession().update(
				"mybatis.xml.SpecialPriceSystemMapper.updateTemplateName",
				specialPriceSystemInfo);
	}

	/**
	 * 导出某一模板下的商品价格
	 * 
	 * @param templateName
	 * @return com.sls.game.pojo.SpecialPriceSystemInfo
	 */
	@Override
	public List<SpecialPriceSystemInfo> queryExportSalePrice(
			SpecialPriceSystemInfo speInfo) {
		List<SpecialPriceSystemInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.SpecialPriceSystemMapper.queryExportSalePrice",
				speInfo);
		return list;
	}

	/**
	 * 
	 * @return
	 */
	@Override
	public List<SpecialPriceSystemInfo> queryTemplateInfo() {
		List<SpecialPriceSystemInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.SpecialPriceSystemMapper.queryTemplateInfo");
		return list;
	}

	@Override
	public List<SpecialPriceSystemInfo> queryTemplateInfoByTemplateCode(
			String templateCode) {
		List<SpecialPriceSystemInfo> list = null;
		list = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.SpecialPriceSystemMapper.queryTemplateInfoByTemplateCode",
						templateCode);
		return list;
	}

	@Override
	public List<SpecialPriceSystemInfo> queryPriceTemplateInfoList() {
		List<SpecialPriceSystemInfo> list = null;
		list = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.SpecialPriceSystemMapper.queryPriceTemplateInfoList");
		return list;
	}

	@Override
	public void updateByGoodsId(SpecialPriceSystemInfo speInfo) {
		this.getSqlSession()
				.update("mybatis.xml.SpecialPriceSystemMapper.updateByGoodsId",
						speInfo);
	}

	@Override
	public void updateByBrandId(SpecialPriceSystemInfo speInfo) {
		this.getSqlSession()
				.update("mybatis.xml.SpecialPriceSystemMapper.updateByBrandId",
						speInfo);

	}
}
